package org.lifxue.jqda.ui.autofield;

import java.util.ArrayList;
import java.util.List;

/**
 * 
 * @Description:
 * @Author: zhangzuoqiang
 * @Date: Sep 26, 2011
 */
public class DefaultCompletionFilter implements CompletionFilter {

	private List<String> listAll;

	public DefaultCompletionFilter() {
		listAll = new ArrayList<String>();
	}

	public DefaultCompletionFilter(List<String> templist) {
		listAll = templist;
	}

	@Override
	public ArrayList<Object> filter(String text) {
		ArrayList<Object> list = new ArrayList<Object>();
		String txt = text.trim().toLowerCase();
		int length = txt.length();
		for (int i = 0; i < listAll.size(); i++) {
			Object o = listAll.get(i);
			String str = o.toString();
			// 输入内容与记录前端比较；如果是空格，就在列表中显示所有
			if (length == 0 || str.startsWith(txt)) {
				list.add(o);
			}
		}
		return list;
	}
}
